﻿if (typeof Axis == "undefined") Axis = {};
if (typeof Axis.View == "undefined") Axis.View = {};
if (typeof Axis.View.Research == "undefined") Axis.View.Research = {};
Axis.View.Research.Detail = {
    Init: function () {
        var thisObj = this;
        if (__Project) {
            var ID = __Project[0].ID;
            var image = __Project[0].Image1;
            var title = __Project[0].Name;
            var summary = __Project[0].Summary;
            var mark = __Project[0].Mark;
            var endDate = $.CFormat.FormatDateSerializer(__Project[0].EndDate);
            $(".content_active").find(".content-asset img").attr("src", image);
            $(".content_active .content-info").find("p.title a:eq(0)").html(title);
            $(".content_active .content-info").find(".summary").html(summary);
            $("._mark_value").text(mark);
            $("._endDate_value").text(endDate);
            thisObj.GetChartData(ID);
        }
    },
    GetChartData: function (pID) {
        var template = ''
        + '<li>'
            + '<div class="data_bg"></div>'
            + '<div class="data_groupName" title="DataGroupName">DataGroupName</div>'
            + '<div class="data_value_list">[List]</div>'
        + '</li><li class="data_separator">&nbsp;</li>';
        var template2 = ''
        + '<div class="data_value">'
            + '<div class="data_name" title="DataName">DataName</div>'
            + '<div class="data_percent">'
                + '<span class="data_percent_left">&nbsp;</span>'
                + '<span class="data_percent_center" style="width:[Percent_Draw]px;">&nbsp;</span>'
                + '<span class="data_percent_right">&nbsp;</span>'
            + '</div>'
            + '<div class="data_percent_value">[Percent]%</div>'
        + '</div>';
        $.Ajax({
            url: "../Research/Service/ResearchService.asmx/GetChartData",
            type: 'POST',
            data: { pProjectID: pID },
            beforeSend: function () {
            },
            success: function (data, textStatus, xhr) {
                if (data) {
                    data = $.findInXml(data);
                    data = eval("(" + data + ")");
                    var categories = [];
                    var series = [];
                    var temp = {};

                    var ret = '';
                    var temp = {};
                    var MaxVoteName = "";
                    var TotalValue = "";
                    $.each(data, function (index, item) {
                        if (typeof temp[item.GroupID] == "undefined") {
                            temp[item.GroupID] = {};
                            temp[item.GroupID].GroupName = "";
                            temp[item.GroupID].Data = [];
                        }

                        temp[item.GroupID].GroupName = item.GroupName;
                        temp[item.GroupID].Data.push(item);
                        if (item.IsMaxVote) {
                            MaxVoteName = item.Name;
                            TotalValue = item.TotalValue;
                        }
                    });

                    $.each(temp, function (key, item) {
                        var groupName = item.GroupName;
                        var ret2 = template.replace(/DataGroupName/g, groupName);
                        var ret3 = "";
                        $.each(item.Data, function (index, item2) {
                            ret3 += template2.replace(/DataName/g, item2.Name);
                            ret3 = ret3.replace("[Percent]", item2.Percent);
                            ret3 = ret3.replace("[Percent_Draw]", item2.Percent * 2.0);
                        });
                        ret2 = ret2.replace("[List]", ret3);
                        ret += ret2;
                    });
                  /*  */
                    $(".content_active_detail_list").html(ret);
                    $(".rs_result .total_value").text(TotalValue);
                    $(".rs_result .max_vote_name").text(MaxVoteName);
                }
            },
            error: function (xhr, textStatus, errorThrown) { }
        });

    }
};
$(function () {
    Axis.View.Research.Detail.Init();
    window.scrollTo(0, document.body.scrollHeight / 5);
});